/**
 @ Name：layui.stepper //元素步进器
 @ Author：alen
 @ License：MIT 
 */
layui.define("jquery", function (exports) {
    var $ = layui.$,
        obj = {
            stepper: function (container, slider, prev, next, step) {
                var innerWidth = $(slider).outerWidth(),
                    outerWidth = $(container).width(),
                    diff = outerWidth - innerWidth; //负值
                $(window).resize(function () {
                    outerWidth = $(container).width();
                    diff = outerWidth - innerWidth; //负值
                });
                $(prev).click(function () {
                    var offsetLeft = $(slider).position().left;
                    if (offsetLeft < -step) {
                        $(slider)
                            .stop()
                            .animate({ left: "+=" + step + "px" }, "fast");
                    } else {
                        $(slider)
                            .stop()
                            .animate({ left: 0 }, "fast");
                    }
                });
                $(next).click(function () {
                    var offsetLeft = $(slider).position().left;
                    if (diff - offsetLeft > -step) {
                        $(slider)
                            .stop()
                            .animate({ left: diff }, "fast");
                    } else {
                        $(slider)
                            .stop()
                            .animate({ left: "-=" + step + "px" }, "fast");
                    }
                });
            }
        };
    exports("stepper", obj);
});  